home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
Vector.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
3KB
|
132 lines
class Vector
{
static var ZERO = new Vector(0,0,0);
static var VECPX = new Vector(1,0,0);
static var VECNX = new Vector(-1,0,0);
static var VECPY = new Vector(0,1,0);
static var VECNY = new Vector(0,-1,0);
static var VECPZ = new Vector(0,0,1);
static var VECNZ = new Vector(0,0,-1);
var x = 0;
var y = 0;
var z = 0;
function Vector(x, y, z)
{
if(x || y || z)
{
this.x = !x ? 0 : x;
this.y = !y ? 0 : y;
this.z = !z ? 0 : z;
}
}
function loc(x, y, z)
{
this.x = x;
this.y = y;
this.z = z;
}
function copy()
{
return new Vector(this.x,this.y,this.z);
}
function copyTo(a)
{
a.x = this.x;
a.y = this.y;
a.z = this.z;
}
function copyFrom(a)
{
this.x = a.x;
this.y = a.y;
this.z = a.z;
}
function distanceToVector(a)
{
var _loc4_ = a.x - this.x;
var _loc3_ = a.y - this.y;
var _loc2_ = a.z - this.z;
return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_ + _loc2_ * _loc2_);
}
function distanceToCoordinates(x, y, z)
{
var _loc4_ = this.x - x;
var _loc3_ = this.y - y;
var _loc2_ = this.z - z;
return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_ + _loc2_ * _loc2_);
}
function get magnitude()
{
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
}
function get length()
{
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
}
function set length(newLength)
{
var _loc2_ = newLength / Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
this.x *= _loc2_;
this.y *= _loc2_;
this.z *= _loc2_;
}
function dot(v)
{
return this.x * v.x + this.y * v.y + this.z * v.z;
}
function cross(v)
{
if(!v)
{
v = Vector.VECPZ;
}
return new Vector(this.y * v.z - this.z * v.y,this.z * v.x - this.x * v.z,this.x * v.y - this.y * v.x);
}
function normalize()
{
var _loc2_ = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
this.x /= _loc2_;
this.y /= _loc2_;
this.z /= _loc2_;
return this;
}
function getNormalized()
{
var _loc2_ = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
return new Vector(this.x / _loc2_,this.y / _loc2_,this.z / _loc2_);
}
function multiply(scalar)
{
this.x *= scalar;
this.y *= scalar;
this.z *= scalar;
}
function divide(scalar)
{
if(!scalar)
{
this.x = 0;
this.y = 0;
this.z = 0;
return undefined;
}
this.x /= scalar;
this.y /= scalar;
this.z /= scalar;
}
function reverse()
{
this.x *= -1;
this.y *= -1;
this.z *= -1;
}
function getReversed()
{
return new Vector(- this.x,- this.y,- this.z);
}
function toString()
{
return "Vector(" + this.x + "," + this.y + "," + this.z + ")";
}
}